package cn.seocoo.platform.api.util;

/**
 * 自定义响应数据结构
 * 这个类是提供给门户，ios，安卓用的
 * 200：表示成功
 * 201：请求不在大赛设置的时间范围内
 * 500：表示错误，错误信息在msg字段中
 * 501：bean验证错误，不管多少个错误都以map形式返回
 * 502：拦截器拦截到用户token出错
 * 555：异常抛出信息
 */
public class JSONResult {


  public static final String ERROR_MSG = "网络波动,请稍后再试";

  public static final String DELETE_MSG = "清空成功";

  public static final String SUBMIT_SUCCESS_MSG = "信息提交成功";
  public static final String SUBMIT_ERROR_MSG = "信息提交失败";

  public static final String NOT_FOUND_USER = "用户不存在";

  // 响应业务状态
  private Integer status;

  // 响应消息
  private String msg;

  // 响应中的数据
  private Object data;

  public static JSONResult build(Integer status, String msg, Object data) {
    return new JSONResult(status, msg, data);
  }

  public static JSONResult ok(Object data) {
    return new JSONResult(data);
  }

  public static JSONResult ok() {
    return new JSONResult(null);
  }

  public static JSONResult errorMsg(String msg) {
    return new JSONResult(500, msg, null);
  }

  public static JSONResult errorMsg(String msg, int erroCode) {
    return new JSONResult(erroCode, msg, null);
  }

  public static JSONResult errorMap(Object data) {
    return new JSONResult(501, "error", data);
  }

  public static JSONResult errorTokenMsg(String msg) {
    return new JSONResult(502, msg, null);
  }

  public static JSONResult errorException(String msg) {
    return new JSONResult(555, msg, null);
  }

  public JSONResult() {

  }

  public JSONResult(Integer status, String msg, Object data) {
    this.status = status;
    this.msg = msg;
    this.data = data;
  }

  public JSONResult(Object data) {
    this.status = 200;
    this.msg = "OK";
    this.data = data;
  }

  public Boolean isOK() {
    return this.status == 200;
  }

  public Integer getStatus() {
    return status;
  }

  public void setStatus(Integer status) {
    this.status = status;
  }

  public String getMsg() {
    return msg;
  }

  public void setMsg(String msg) {
    this.msg = msg;
  }

  public Object getData() {
    return data;
  }

  public void setData(Object data) {
    this.data = data;
  }

}
